package com.test.test;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileReader;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class ForkJoinDemo {

    public static void main(String[] args) {
        FileReader fileReader = new FileReader("C:\\Users\\41636\\Desktop\\large_text_file.txt");
        //总数
        int totalCount = fileReader.readLines().size();
        System.out.println(totalCount);


    }

    public static void generateBigFile() {
        // 文件路径和名称
        String filePath = "C:\\Users\\41636\\Desktop\\large_text_file.txt";
        // 目标文件大小，单位为字节（1GB）
        long targetSizeBytes = 1024L * 1024L * 1024L;

        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter(filePath));
            long currentSize = 0;

            // 每次写入一行 1MB 的数据，直到达到目标大小
            while (currentSize < targetSizeBytes) {
                // 每行写入 1MB 的数据
                String line = generateRandomLine(1024 * 1024);
                writer.write(line);
                writer.newLine();
                currentSize += line.getBytes().length + 1;
            }

            writer.close();
            System.out.println("File created successfully.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 生成随机字符串
     *
     * @param length
     * @return
     */
    private static String generateRandomLine(int length) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            sb.append((char) ('a' + Math.random() * 26));
        }
        return sb.toString();
    }

}


